// 所有模块都通过 define 来定义
define(function(require, exports, module) {
	
	require('jquery');
	require('./css/upload.css');
	require('./src/default.css');
	require('./src/kindeditor-min.js');
	require.async('./src/lang/zh_CN.min.js');
	
	/**
	 * config = {dom:'',clickdom:''}
	 */
	
	exports.run = function(){
		var config = {dom:'#colorcode',clickdom:'#colorpicker'}; //配置
		var colorpicker;
		

		KindEditor.ready(function(K) {
			var colorpicker;
			K(config.clickdom).bind('click', function(e) {
				e.stopPropagation();
				if (colorpicker) {
					colorpicker.remove();
					colorpicker = null;
					return;
				}
				var colorpickerPos = K(config.clickdom).pos();
				colorpicker = K.colorpicker({
					x : colorpickerPos.x,
					y : colorpickerPos.y + K(config.clickdom).height(),
					z : 19811214,
					selectedColor : 'default',
					noColor : '无颜色',
					click : function(color) {
						K(config.dom).val(color);
						K(config.clickdom).css('background-color',color);
						colorpicker.remove();
						colorpicker = null;
					}
				});
			});
			K(document).click(function() {
				if (colorpicker) {
					colorpicker.remove();
					colorpicker = null;
				}
			});
		});
	
	
	}
});